#ifndef __CONVERSION_HXX__
#define __CONVERSION_HXX__

#include "mytypes.h"
#include "mydll.h"

#if defined(__cplusplus)
extern "C"
{
#endif
  /*///////////////////////////////////////////////////////////////////////////
  // Byte2Hex:
  //
  // Takes a byte as parameter and return the hexa representation in ASCII into 
  // a short integer (16 bits).
  // 
  // For example, if value = 50 then the return value will be 0x3332 or 13106
  // in decimal.
  // 
  // 0x33 represents the ASCII value for '3', 0x32 represents the ASCII value 
  // for '2'. '32' if the hexa value of the decimal value of 50.
  // It returns a short int and not a char[2] in order to be thread safe and 
  // not return the address of a freed memory block reserved into the stack.
  //
  // Below is an example on how to use this function:
  //
  // short int res;
  // const char *p=(const char *) &res;
  // res=Byte2Hex(50);
  // *out<<p[0]<<p[1];
  //
  // Should print '32' on STDOUT. */
  
  tUInt16 Byte2Hex(tByte value);


  /*///////////////////////////////////////////////////////////////////////////
  // Hex2Byte:
  //
  // Takes an array of 2 bytes containing the ASCII representation of a byte 
  // value and returns it value (between 0 and 255).
  // 
  // For example, if value[0]='3' and value[1]='2' then this function returns 50.
  //
  // NOTE: It is not required that the input array should be NULL terminated. */
  tByte Hex2Byte(const tByte value[2]);



  /*///////////////////////////////////////////////////////////////////////////
  // Convert the input array of binary value 'binval' of size 'len' bytes 
  // into the corresponding ASCII representation containing hexadecimal value.
  //
  // Two versions of this function is provided. The first one 'Bin2Ascii'
  // puts the result into 'out'. The number of written bytes is exactly
  // the double of the value available in 'len' plus one for the null character.
  //
  // Memory allocation of the buffers 'binbuf' and 'out'  is the 
  // responsibility of the caller. No check is performed.
  //
  // The second version 'sBin2Ascii' does the same but instead of putting
  // the result into a given array, a statically allocated array is returned 
  // instead containing the hexadecimal representation.
  //
  // Note that in both version, the hexadecimal representation ends with the
  // null ('\0') character so that it can be directly be used into a printf
  // function.
  //
  ///////////*/
  void Bin2Ascii(tByte *binbuf, tUInt32 len, tByte *out);

  tByte *sBin2Ascii(tByte *binbuf, tUInt32 len);

  /*///////////////////////////////////////////////////////////////////////////
  // Convert the input array of ASCII value 'asciibuf' of size 'len' bytes 
  // representing hexadecimal values into the corresponding binary array.
  // Result is put into out and outlen represent the number of bytes newly 
  // written into 'out'. If not error, then the value of 'len' should be 
  // exactly the double of 'outlen'.
  //
  // Memory allocation of the buffers 'asciival' and 'out'  is the 
  // responsibility of the caller. No check is performed.
  ///////////*/
  void Ascii2Bin(tByte *asciibuf, tUInt32 len, tByte *out);


  

#if defined(__cplusplus)
} /*  extern "C" */
#endif

#endif /* __CONVERSION_HXX__ */

